﻿using HomagGroup.Base.UI;
using HomagChina.CCT.BaseUI.DataModel;
using System;

namespace HomagChina.CCT.BaseUI.ViewModel
{
    public class HomeDailyCounterDialogViewModel : NotifyPropertyChangedBase
    {
        #region

        //Handle
        //private InsertInfoHandle Handle_Insert;

        //private SearchInfoHandle Handle_Search;
        //private ModifyInfoHandle Handle_Modify;
        //private CommonHandle commonHandle;
        #endregion

        //属性
        #region
        private string _Reference;
        private string _Length;
        private string _Width;
        private string _Thickness;
        private string _Location;
        private string _Feature;
        private Boolean _State;
        private Boolean _AgainstState;

        //是否为编辑状态
        private bool _IsEdit;

        public string Width
        { get => _Width; set { _Width = value; OnPropertyChanged(); } }

        public string Thickness
        { get => _Thickness; set { _Thickness = value; OnPropertyChanged(); } }

        public string Feature
        { get => _Feature; set { _Feature = value; OnPropertyChanged(); } }

        public string Reference
        { get => _Reference; set { _Reference = value; OnPropertyChanged(); } }

        public string Location
        { get => _Location; set { _Location = value; OnPropertyChanged(); } }

        public string Length
        { get => _Length; set { _Length = value; OnPropertyChanged(); } }

        public Boolean State
        { get => _State; set { _State = value; OnPropertyChanged(); } }

        public bool AgainstState
        { get => _AgainstState; set { _AgainstState = value; OnPropertyChanged(); } }

        public bool IsEdit
        { get => _IsEdit; set { _IsEdit = value; OnPropertyChanged(); } }

        //提交
        public RelayCommand ApplyCommand { get; }

        #endregion

        //构造函数
        public HomeDailyCounterDialogViewModel(SetttingsModel SelectItem, Boolean IsEdit)
        {
            //if (SelectItem != null)
            //{
            //    this.IP = SelectItem.Ip;
            //    this.ID = SelectItem.Id;
            //    this.Port = SelectItem.Port.ToString();
            //    this.Topic = SelectItem.Topic;
            //    this.Describe = SelectItem.Describe;
            //    this.State = SelectItem.State == 0;
            //    this.AgainstState = SelectItem.State == 1;
            //}
            //this.IsEdit = IsEdit;
            //提交
            ApplyCommand = new RelayCommand(Apply);
            //工具类函数
            //commonHandle = new CommonHandle();
            ////查询
            //Handle_Search = new SearchInfoHandle();
            ////写入
            //Handle_Insert = new InsertInfoHandle();
            ////更新
            //Handle_Modify = new ModifyInfoHandle();
        }

        //提交函数
        private void Apply()
        {
            //commonHandle.CloseDiaLog("SettingsDialog");
            //var t = new T_SettingsConfig
            //{
            //    Id = this.ID,
            //    Ip = this.IP,
            //    Port = this.Port.ToInt16(),
            //    Topic = this.Topic,
            //    Describe = this.Describe,
            //    State = this.State ? 0 : 1,
            //    CreateTime = DateTime.Now,
            //    UpdateTime = DateTime.Now
            //};

            //if (IsEdit)
            //{
            //    if (Handle_Modify.ModifySettingsInfo(t))
            //    {
            //        HomagGroup.Base.UI.Windows.MessageBox.Show("Congratulations, the information has been successfully modified！");
            //        new SettingsViewModel().Refresh();
            //        commonHandle.CloseDiaLog("SettingsDialog");
            //    }
            //    else
            //    {
            //        HomagGroup.Base.UI.Windows.MessageBox.Show("Sorry, information modification failed, please try again or contact the administrator!");
            //    }
            //}
            //else
            //{
            //    if (Handle_Insert.InsertSettingsHandle(t))
            //    {
            //        commonHandle.CloseDiaLog("SettingsDialog");
            //        HomagGroup.Base.UI.Windows.MessageBox.Show("Congratulations, information added successfully！");
            //    }
            //    else
            //    {
            //        HomagGroup.Base.UI.Windows.MessageBox.Show("Sorry, information addition failed, please try again or contact administrator！");
            //    }

            //}
        }
    }
}